package com.spring.lesson001.demo4;

import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author vhans
 */
public class ScopeTest {
    ClassPathXmlApplicationContext context;

    @Before
    public void before() {
        System.out.println("spring容器准备启动。。。");
        String beanXml = "bean0014.xml";
        context = new ClassPathXmlApplicationContext(beanXml); // 在启动过程中进行bean装载
        System.out.println("spring容器启动完毕！！！");
    }

    @Test
    public void singletonBean() {
        System.out.println("---------单例bean，每次获取的bean一样");
        System.out.println(context.getBean("singletonBean"));
        System.out.println(context.getBean("singletonBean"));
        System.out.println(context.getBean("singletonBean"));
    }

    @Test
    public void prototypeBean() {
        System.out.println("---------多例bean，每次获取的bean都不一样,并且每次获取的时候会调用一次构造函数");
        System.out.println(context.getBean("prototypeBean"));
        System.out.println(context.getBean("prototypeBean"));
        System.out.println(context.getBean("prototypeBean"));
    }
}
